import numpy as np
from math import sqrt

def accuracy_score(y_true,y_predict):
    assert y_true.shape[0]==y_predict.shape[0]#确保预测值与真实值特征数量相同

    return np.sum(y_true==y_predict)/len(y_true)

def mean_squared_error(y_true,y_predict):#MSE评价
    assert len(y_true)==len(y_predict)
    return np.sum((y_true-y_predict)**2)/len(y_true)

def root_mean_squared_error(y_true,y_predict):#RMSE评价
    return sqrt(mean_squared_error(y_true,y_predict))

def mean_absolute_error(y_true,y_predict):#MAE评价
    assert len(y_true)==len(y_predict)
    return np.sum(np.absolute(y_true-y_predict))/len(y_true)

def r2_score(y_true,y_predict):#R评价
    return 1-mean_squared_error(y_true,y_predict)/np.var(y_true)